<%--
  Created by IntelliJ IDEA.
  User: pc
  Date: 2020/11/23
  Time: 19:35
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>客户表</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layui.css">
    <script src="${pageContext.request.contextPath}/layui/layui.js"></script>
</head>
<body>

<!--修改 只能修改状态 密码注册要在前端进行操作-->

<div id="updGustForm">
    <form class="layui-form" action="" lay-filter="modify">
        <div class="layui-form-item">
            <label class="layui-form-label">id</label>
            <div class="layui-input-block">
                <input type="text"  name="id"   disabled lay-verify="required" disabled  autocomplete="off" class="layui-input">
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-block">
                <input type="text"  name="name"  disabled lay-verify="required"  autocomplete="off" class="layui-input">
            </div>
        </div>



        <div class="layui-form-item">
            <label class="layui-form-label">idcard</label>
            <div class="layui-input-block">
                <input type="text" name="idcard"   disabled  autocomplete="off" class="layui-input">
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label">img</label>
            <div class="layui-input-block">
                <input type="text" name="img"  disabled   autocomplete="off" class="layui-input">
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label">选择框</label>
            <div class="layui-input-block">
                <select name="status" lay-verify="required">
                            <option value="0">正常</option>
                            <option value="1">禁用</option>
                </select>
            </div>
        </div>



        <div class="layui-form-item" style="margin-top: 10px">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo" >立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>

    </form>
</div>



<table class="layui-hide" id="test" lay-filter="test"></table>





<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>






<script>
    layui.use(['table','form','layer','jquery'], function(){
        var table = layui.table;
        var form = layui.form;
        var layer = layui.layer;
        var $ = layui.jquery;
        $("#updGustForm").hide();

        table.render({
            elem: '#test'
            ,url:'/seluser'
            ,title: '客户表'
            ,cols: [[
                 {field:'id', title:'ID', fixed: 'left', unresize: true, sort: true}
                ,{field:'name', title:'用户名'}
                ,{field:'idcard', title:'身份证号'}
                ,{field:'img', title:'照片'}
                ,{field:'status', title:'状态', templet: function(res){
                    var d= res.status;
                    if (d==0){
                        return "正常";
                    }else {
                        return "禁用";
                    }

                    }}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:150}
            ]]
            ,page: true
        });



        //监听行工具事件
        table.on('tool(test)', function(obj){
            var data = obj.data;
            //console.log(obj)
            if(obj.event === 'del'){
                layer.confirm('真的删除行么', function(index){
                    obj.del();
                    layer.close(index);
                });
            } else if(obj.event === 'edit'){
                // layer.prompt({
                //     formType: 2
                //     ,value: data.email
                // }, function(value, index){
                //     obj.update({
                //         email: value
                //     });
                //     layer.close(index);
                // });

                form.val("modify",data);

                layer.open({
                    type: 1,
                    skin: 'layui-layer-rim', //加上边框
                    area: ['800px', '600px'], //宽高
                    content: $("#updGustForm")
                });

                //提交按钮
                form.on('submit(formDemo)', function(data){
                    //layer.msg(JSON.stringify(data.field));
                    //1.将获取到到的数据保存到数据库
                    $.ajax({
                        url:"/upduser",
                        data:data.field,
                        dataType: "JSON",
                        type:"post",
                        success:function (ret){
                            if (ret>0){
                                alert("成功");
                            }
                        },error:function (){
                            alert("错误");
                        }
                    })
                    //刷新表单
                    return true;
                });




            }
        });
    });
</script>




</body>
</html>
